<?php
namespace Home\Controller;
use Think\Controller;
class SenicController extends BaseController {
    private $perpage = 6;
    private $M;
    public function _initialize(){
        $this->M = M("Senic");
    }
    public function details(){
        $this->display();
    }
    public function index(){
        $da = M("Senic") -> select();
        $this -> assign("senic",$da);
        echo R("Navlink/index");
		 $count = $this->M->count();    // 总记录数
        $pages = ceil($count / $this->perpage);
        if(empty($nowpage)){
            $nowpage = 1;
        }
        $Page = new \Think\Page($count, $this->perpage);
        $Page->setConfig("prev", "上一页");
        $Page->setConfig("next", "下一页");
        $this->M->alias("s")->join(array(
            "left JOIN y_area a on a.id=s.province",
            "left join y_area b on b.id=s.city",
            "LEFT JOIN y_area c on c.id=s.district",
            "left JOIN __THEME__ t on t.id=s.theme_id",
            "left join __SENIC_PIC__ p on p.senic_id=s.id"
        ))->field(array(
            "s.*",
            "a.name"=> "province",
            "b.name"=> "city",
            "c.name"=> "district",
            "t.value"=> "value",
            "p.picture"=> "picture"
        ));
        $list = $this->M->limit($Page->firstRow.','.$Page->listRows)->select();   // 每页的数据数组
        $show = $Page->show();  // 页码链接内容
        $this->assign("count", $count);
        $this->assign("list", $list);
        $this->assign("page", $show);
        $this->assign("pages", $pages);
        $this->assign("nowpage", $nowpage);
        $this->display();
    }
    public function senic(){
        echo R("Navlink/index");
        $rm = M("senic");
        $id = I("id");
        if($id==""){
            $this->redirect("/Home/Senic",array(),0,"");
        }
        $list =$rm->where("id=".$id)->find();
        $this->assign("list",$list);
        $this->display();
     }
}